package com.boilermaker.demo.controller;

import com.boilermaker.demo.common.Constants;
import com.boilermaker.demo.service.UserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public boolean login(@RequestParam("name") String userName, String password, HttpSession session) {
        boolean ok = userService.checkLogin(userName, password);
        if (ok) {
            session.setAttribute(Constants.SESSION_USER_KEY, userService.selectUserByName(userName));
            return true;
        }
        return false;
    }
}
